/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.dao.impl;

import es.silenus.detecta.dao.QuestionDAO;

import es.silenus.detecta.model.Question;

import org.hibernate.Session;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * DOCUMENT ME!
 *
 * @author <a href="mailto:dgarcia@silenus-consultoria.es">Daniel Garc&iacute;a</a>
 *
 * @since 02-abr-2009 12:41:39
 */
public class QuestionDAOImpl extends ReadWriteDAOImpl<Question, Long> implements QuestionDAO {
	/**
	 * Finds a question by its code.
	 *
	 * @param code the code.
	 * @param surveyId the survey id.
	 *
	 * @return the question.
	 */
	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	public Question findByCode(String code, int surveyId) {
		Session session = null;

		try {
			session = getSession();

			return (Question)session.getNamedQuery(Question.class.getName() + ".findByCode").setString("code", code)
															.setInteger("surveyId", surveyId).uniqueResult();
		} finally {
			releaseSession(session);
		}
	}
}
